﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace CapaPresentacion.Controles
{
    /// <summary>
    /// Lógica de interacción para CargadorListaHermanos.xaml
    /// </summary>
    public partial class CargadorListaHermanos : UserControl
    {

        public static readonly DependencyProperty FuenteDatosProperty = DependencyProperty.Register("FuenteDatos", typeof(ObservableCollection<string>), typeof(CargadorListaHermanos));

        public CargadorListaHermanos()
        {
            InitializeComponent();

            Binding b1 = new Binding();
            b1.Source = this;
            b1.Path = new PropertyPath(CargadorListaHermanos.FuenteDatosProperty);
            b1.Mode = BindingMode.TwoWay;
            this.listaDatos.SetBinding(ListBox.ItemsSourceProperty, b1);
        }


       
        private void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            bool existe = false;
            foreach (var v in this.FuenteDatos)
            {
                if (v.ToLower() == this.txtNombreHermano.Text.Trim().ToLower() + " / " +  this.txtEdadHermano.Text.Trim())
                    existe = true;

            }
            if (!existe)
            {
                this.FuenteDatos.Add(this.txtNombreHermano.Text.Trim().ToLower() + " / " + this.txtEdadHermano.Text.Trim());
                this.txtNombreHermano.Text = String.Empty;
                this.txtEdadHermano.Text = String.Empty;
            }
        }

        private void btnQuitar_Click(object sender, RoutedEventArgs e)
        {
            if (this.listaDatos.SelectedIndex != -1)
                this.FuenteDatos.RemoveAt(this.listaDatos.SelectedIndex);

        }


        public ObservableCollection<string> FuenteDatos
        {
            get
            {
                return (ObservableCollection<string>)this.GetValue(FuenteDatosProperty);
            }

            set { SetValue(FuenteDatosProperty, value); }

        }


        private void Numerico_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key >= Key.D0 && e.Key <= Key.D9 || e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9 || e.Key == Key.Space)
                e.Handled = false;
            else
                e.Handled = true;
        }








    }
}
